﻿//
// $HeadURL: http://codeka-memcache.googlecode.com/svn/trunk/Codeka.Memcache.Tests/BaseTestClass.cs $
// $Revision: 2 $
// $Author: dean.codeka $     $Date: 2010-02-13 11:41:50 +0000 (Sat, 13 Feb 2010) $
//
// Copyright © 2009-2010 Dean Harding, all rights reserved.
//

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.IO;

namespace Codeka.Memcache.Tests
{
    /// <summary>
    /// This is the base class for our unit tests. It adds some functionality that's
    /// useful (like the ability to automatically delete files when the test is
    /// finished, etc)
    /// </summary>
    [TestClass]
    public class BaseTestClass
    {
        private static List<string> filesToDelete;

        /// <summary>
        /// Adds a filename to a list of files you want us to delete when the
        /// test has finished.
        /// </summary>
        public static void AddFileToBeDeleted(string fileName)
        {
            if (filesToDelete == null)
                filesToDelete = new List<string>();

            filesToDelete.Add(fileName);
        }

        /// <summary>
        /// This is called automatically when a test finishes. We'll do our
        /// cleanup stuff.
        /// </summary>
        [TestCleanup]
        public void TestFinished()
        {
            if (filesToDelete != null)
            {
                foreach (var fileName in filesToDelete)
                {
                    File.Delete(fileName);
                }

                filesToDelete = null;
            }
        }
    }
}
